using System;
using Xunit;

namespace muduoDotNet.Tests
{
    public class TimeStampTest
    {
        [Fact]
        public void TestTimeStampCreation()
        {
            var timestamp = TimeStamp.Now();
            Assert.True(timestamp.IsValid);
            Assert.True(timestamp.MicroSecondsSinceEpoch > 0);
        }

        [Fact]
        public void TestTimeStampInvalid()
        {
            var invalid = TimeStamp.Invalid;
            Assert.False(invalid.IsValid);
            Assert.Equal(0, invalid.MicroSecondsSinceEpoch);
        }

        [Fact]
        public void TestTimeStampComparison()
        {
            var timestamp1 = TimeStamp.Now();
            System.Threading.Thread.Sleep(1); // 确保时间差
            var timestamp2 = TimeStamp.Now();
            
            Assert.True(timestamp2 > timestamp1);
            Assert.True(timestamp1 < timestamp2);
            Assert.False(timestamp1 == timestamp2);
        }

        [Fact]
        public void TestTimeStampAddSeconds()
        {
            var timestamp = TimeStamp.Now();
            var future = timestamp.AddSeconds(1.5);
            
            Assert.True(future > timestamp);
            
            var difference = future.SecondsSinceEpoch - timestamp.SecondsSinceEpoch;
            Assert.True(Math.Abs(difference - 1.5) < 0.001); // 允许小的精度误差
        }

        [Fact]
        public void TestTimeStampAddMilliseconds()
        {
            var timestamp = TimeStamp.Now();
            var future = timestamp.AddMilliseconds(100);
            
            Assert.True(future > timestamp);
        }

        [Fact]
        public void TestTimeStampToDateTime()
        {
            var timestamp = TimeStamp.Now();
            var dateTime = timestamp.ToDateTime();
            
            Assert.True(dateTime.Kind == DateTimeKind.Utc);
        }
    }
}